<?php

namespace app\models;

use Yii;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
/**
 * This is the model class for table "bill".
 *
 * @property integer $billid
 * @property string $title
 * @property double $money
 * @property  integer $user_id
 * @property integer $created_at
 * @property integer $updated_at
 */
class Bill extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'bill';
    }
    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'attributes'=>[
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
                ],
            ]
        ];
    }
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['title', 'money','user_id'], 'required'],
            [['money'], 'number'],
            [['title'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'billid' => '记录id',
            'title' => '标题',
            'money' => '金额',
            'user_id'=>'用户',
            'created_at' => '创建时间',
            'updated_at' => '修改时间',
        ];
    }

    public static function log($title,$money,$user_id)
    {
        $model = new self();
        $model->title = $title;
        $model->money = $money;
        $model->user_id = $user_id;
        $model->save(false);
    }
}
